using System;
using System.Windows.Input;
using CommunityToolkit.Mvvm.Input;

namespace CANBusTools.ViewModels
{
    public class LightControlViewModel : ViewModelBase
    {
        private readonly object _busHelper;

        private bool _leftLightOn;
        public bool LeftLightOn
        {
            get => _leftLightOn;
            set
            {
                if (_leftLightOn != value)
                {
                    _leftLightOn = value;
                    OnPropertyChanged(nameof(LeftLightOn));
                }
            }
        }

        private bool _rightLightOn;
        public bool RightLightOn
        {
            get => _rightLightOn;
            set
            {
                if (_rightLightOn != value)
                {
                    _rightLightOn = value;
                    OnPropertyChanged(nameof(RightLightOn));
                }
            }
        }

        public ICommand LeftLightOnCommand { get; }
        public ICommand LeftLightOffCommand { get; }
        public ICommand RightLightOnCommand { get; }
        public ICommand RightLightOffCommand { get; }

        public LightControlViewModel(object busHelper)
        {
            _busHelper = busHelper;
            LeftLightOnCommand = new RelayCommand(() => SetLeftLight(true));
            LeftLightOffCommand = new RelayCommand(() => SetLeftLight(false));
            RightLightOnCommand = new RelayCommand(() => SetRightLight(true));
            RightLightOffCommand = new RelayCommand(() => SetRightLight(false));
        }

        private void SetLeftLight(bool on)
        {
            LeftLightOn = on;
            // TODO: 替换为实际调用 _busHelper.LeftLightSwitch(on ? "2" : "1");
            Console.WriteLine($"Left light turned {(on ? "ON" : "OFF")}");
        }

        private void SetRightLight(bool on)
        {
            RightLightOn = on;
            // TODO: 替换为实际调用 _busHelper.RightLightSwitch(on ? "2" : "1");
            Console.WriteLine($"Right light turned {(on ? "ON" : "OFF")}");
        }
    }
}
